package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.data.PhotoInfo;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

/**
 * Created by windo on 16/5/11.
 */
public class ZhaopianDetailTask extends CouponHttpBaseTask{
    private String imageId;

    public ZhaopianDetailTask(String id) {
        super(TaskType.ZAOPIANDETAIL_TASK);
        imageId = id;
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT){
            CouponHttpRequest request = new CouponHttpRequest(RequestType.ZAOPIANDETAIL_REQUEST);
            JSONObject json = new JSONObject();
            json.put("imageId",imageId);
            request.setData(json.toString());
            request.setApiNo(ApiNo.ZAOPIANDETAIL);
            addRequest(request);
        }
    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject res = response.getBody();
        PhotoInfo info= null;
        if (res != null){
           info =  JSON.parseObject(res.getString("image"), PhotoInfo.class);
        }

        notifyTaskCompleted(TaskResultCode.SUCCESS,info);
    }
}
